package com.imay.live.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.live.R;
import com.imay.live.helper.LevelHelper;
import com.imay.live.model.SearchResultModel;
import com.imay.live.model.UserModel;
import com.imay.live.utils.GlideUtil;

import java.util.List;

/**
 * Created by liangzhenxiong on 2017/4/6 0006.
 * 搜索
 */

public class SearchLinearAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {


    public final static int VIEWTYPE_LINEAR_CONTENT = 0x113;//推荐结果


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public SearchLinearAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(VIEWTYPE_LINEAR_CONTENT, R.layout.searchresult_item);

    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        if (item.getItemType() == VIEWTYPE_LINEAR_CONTENT) {
            SearchResultModel searchResultModel = (SearchResultModel) item;
            UserModel userModel = searchResultModel.getUser();
            if (userModel != null) {
                TextView tv_nick = helper.getView(R.id.tv_nick);
                tv_nick.setText(userModel.getNick());;
                helper.setImageResource(R.id.iv_vip, LevelHelper.getVIPIcon(userModel.getVip()));
                helper.setText(R.id.tv_meihao, helper.getConvertView().getResources().getString(R.string.search_useruid, userModel.getRoomId()));
                helper.setText(R.id.tv_live_level, String.valueOf(userModel.getLiveLevel()));
                helper.setText(R.id.tv_user_level, String.valueOf(userModel.getUserLevel()));
                helper.setBackgroundRes(R.id.tv_user_level, LevelHelper.getUserLevelResId(userModel.getUserLevel()));
                helper.setBackgroundRes(R.id.tv_live_level, LevelHelper.getLiveLevelResId(userModel.getLiveLevel()));
                ImageView imageView = helper.getView(R.id.iv_searchhead);
                GlideUtil.loadCircleImage(imageView,userModel.getImgHead(),R.mipmap.pnl_00_head108);
                helper.addOnClickListener(R.id.rl_left);
                helper.addOnClickListener(R.id.search_right);
                helper.setVisible(R.id.iv_live, userModel.getLiveStatus() == 1);
                if (userModel.myFollow){
                    helper.setImageResource(R.id.iv_add,R.mipmap.ico_00_jinru_btn);
                }else {
                    helper.addOnClickListener(R.id.iv_add);
                    helper.setImageResource(R.id.iv_add,R.mipmap.btn_02phbguanzhu);
                }
            }
        }
    }

}
